
export default {
	detect(ua){  
  
      //this为Zepto，给它绑两个属性：一个os，一个browser  
      var detect = {};
      detect.os = {};   
      detect.browser = {};
      detect.app = {};
  
      var Xylc = ua.match(/Xylc\/([\d.]+)/);
      
      var webkit = ua.match(/WebKit\/([\d.]+)/);
  
      var android = ua.match(/(Android)\s+([\d.]+)/);  
  
      var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);  
  
      var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);  
  
      var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
      
	  var wechat = ua.toLowerCase().match(/MicroMessenger/i) == 'micromessenger';
  
      var touchpad = webos && ua.match(/TouchPad/);
  
      var kindle = ua.match(/Kindle\/([\d.]+)/);
  
      var silk = ua.match(/Silk\/([\d._]+)/);  
  
      var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);  
  
      var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);  
  
      var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);  
  
      var playbook = ua.match(/PlayBook/);
  
      var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);  
  
      //比如火狐19,这边firefox是一个数组：["Firefox/19.0","19.0"];  
      var firefox = ua.match(/Firefox\/([\d.]+)/);
  
    // Todo: clean this up with a better OS/browser seperation:  
    // - discern (more) between multiple browsers on android  
    // - decide if kindle fire in silk mode is android or not  
    // - Firefox on Android doesn't specify the Android version  
    // - possibly devide in os, device and browser hashes  
  
    if (detect.browser.webkit = !!webkit) detect.browser.version = webkit[1]  
  
   	if (wechat) detect.app.wechat = true //detect.os.version = android[2] 
   	
   	if (Xylc) detect.app.Xylc = Xylc[1] 
   	
    if (android) detect.os.android = true, detect.os.version = android[2]  
  
    if (iphone) detect.os.ios = detect.os.iphone = true, detect.os.version = iphone[2].replace(/_/g, '.')  
  
    if (ipad) detect.os.ios = detect.os.ipad = true, detect.os.version = ipad[2].replace(/_/g, '.')  
  
    if (webos) detect.os.webos = true, detect.os.version = webos[2]  
  
    if (touchpad) detect.os.touchpad = true  
  
    if (blackberry) detect.os.blackberry = true, detect.os.version = blackberry[2]  
  
    if (bb10) detect.os.bb10 = true, detect.os.version = bb10[2]  
  
    if (rimtabletos) detect.os.rimtabletos = true, detect.os.version = rimtabletos[2]  
  
    if (playbook) detect.browser.playbook = true  
  
    if (kindle) detect.os.kindle = true, detect.os.version = kindle[1]  
  
    if (silk) detect.browser.silk = true, detect.browser.version = silk[1]  
  
    if (!silk && detect.os.android && ua.match(/Kindle Fire/)) detect.browser.silk = true  
  
    //如果chrome有值的话，给browser装两个属性firefix和version  
    if (chrome) detect.browser.chrome = true, detect.browser.version = chrome[1]  
  
    //如果firefox有值的话，给browser装两个属性firefix和version  
    if (firefox) detect.browser.firefox = true, detect.browser.version = firefox[1]  
  
    //os必有一个属性tablet来标示是否是平板  
    detect.os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) || (firefox && ua.match(/Tablet/)))  
  
    //os必有一个属性phone来标示是否是手机，但是有问题：如果是pc的火狐，返回的居然也是true（当然它本身针对移动端的，呵呵，忽略忽略）  
    detect.os.phone  = !!(!detect.os.tablet && (android || iphone || webos || blackberry || bb10 || chrome || firefox))
    
    return detect;
  }  
}